package com.tourlaid.mamagerment.service.impl

import com.tourlaid.mamagerment.entity.Reward
import com.tourlaid.mamagerment.enums.TldExceptionEnum
import com.tourlaid.mamagerment.mapper.RewardMapper
import com.tourlaid.mamagerment.service.RewardService
import com.tourlaid.mamagerment.util.LoginUtil
import com.tourlaid.mamagerment.util.TldException
import org.springframework.stereotype.Service
import java.util.*
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/15.
 */
@Service("rewardService")
class RewardServiceImpl : RewardService {
    override fun queryByThoughtId(thoughtId: Long): List<Reward> {
        return rewardMapper!!.queryByThoughtId(thoughtId)
    }

    @Resource
    val rewardMapper: RewardMapper? = null

    override fun reward(ownUserId: Long?, thoughtId: Long) {
        if (Objects.equals(ownUserId, thoughtId)) throw TldException(TldExceptionEnum.SELF_REWARD)
        var reward = Reward()
        reward.userId = LoginUtil.userId
        reward.thoughtId = thoughtId
        reward.integral = 1 //默认是1
        reward.creator = LoginUtil.userId
        reward.editor = LoginUtil.userId
        rewardMapper!!.insert(reward)
    }
}